import csv
import os
from Predict.models import Covid, forcast_lightgbm, forcast_xgboost,forcast_rnn,forcast_rf,forcast_pr


import django
django.setup()

os.environ.setdefault('DJANGO_SETTINGS_MODULE')


'''
item name
'''

item_bulk = []

with open('./dataset/truthfuldata.csv') as csv_file:
    data = csv.reader(csv_file)
    for row in data:
        item_bulk.append(Covid(area = row[1] , country = row[2] , confirmedCases = row[4] , fatalities = row[5],date=row[3]))

for i in range(1, len(item_bulk)):
    Covid.objects.filter(id=i).create(area    = item_bulk[i].area,
                                      country = item_bulk[i].country,
                                      confirmedCases = item_bulk[i].confirmedCases,
                                      fatalities  = item_bulk[i].fatalities,
                                      date    = item_bulk[i].date,)

#上传多项式模型预测数据至数据库
with open('./dataset/PR_prediction.csv') as csv_file:
    data = csv.reader(csv_file)
    for row in data:
        item_bulk.append(forcast_pr(area = row[3] , country = row[1] , predConfirmedCases = row[4] , predFatalities = row[5],date=row[2]))

for i in range(1, len(item_bulk)):
    forcast_pr.objects.filter(id=i).create(area    = item_bulk[i].area,
                                      country = item_bulk[i].country,
                                      predConfirmedCases = item_bulk[i].predConfirmedCases,
                                      predFatalities  = item_bulk[i].predFatalities,
                                      date    = item_bulk[i].date,)

#上传random forest模型预测数据至数据库
with open('./dataset/RF_prediction.csv') as csv_file:
    data = csv.reader(csv_file)
    for row in data:
        item_bulk.append(forcast_rf(area = row[3] , country = row[1] , predConfirmedCases = row[4] , predFatalities = row[5],date=row[2]))

for i in range(1, len(item_bulk)):
    forcast_rf.objects.filter(id=i).create(area    = item_bulk[i].area,
                                      country = item_bulk[i].country,
                                      predConfirmedCases = item_bulk[i].predConfirmedCases,
                                      predFatalities  = item_bulk[i].predFatalities,
                                      date    = item_bulk[i].date,)

#上传rnn模型预测数据至数据库
with open('./dataset/rnn_prediction.csv') as csv_file:
    data = csv.reader(csv_file)
    for row in data:
        item_bulk.append(forcast_rnn(area = row[1] , country = row[2] , predConfirmedCases = row[4] , predFatalities = row[5],date=row[3]))

for i in range(1, len(item_bulk)):
    forcast_rnn.objects.filter(id=i).create(area    = item_bulk[i].area,
                                      country = item_bulk[i].country,
                                      predConfirmedCases = item_bulk[i].predConfirmedCases,
                                      predFatalities  = item_bulk[i].predFatalities,
                                      date    = item_bulk[i].date,)

#上传XGBoost模型预测数据
with open('./dataset/XGB_prediction.csv') as csv_file:
    data = csv.reader(csv_file)
    for row in data:
        item_bulk.append(forcast_xgboost(area = row[0] , country = row[2] , predConfirmedCases = row[3] , predFatalities = row[4],date=row[1]))

for i in range(1, len(item_bulk)):
    forcast_xgboost.objects.filter(id=i).create(area    = item_bulk[i].area,
                                      country = item_bulk[i].country,
                                      predConfirmedCases = item_bulk[i].predConfirmedCases,
                                      predFatalities  = item_bulk[i].predFatalities,
                                      date    = item_bulk[i].date,)
